package metadata;

import java.util.*;

import utility.*;

public class Column {
	
	//private vars
	private String name			= "";
	private String datatype		= "";
	private boolean notnull		= false;
	
	private List<String> data	= null;
	
	
	//constructors
	/**
	 * Creates a new Column object with the given name, datatype and notNull attribute. <br>
	 * <br>
	 * Use it's static String DATATYPE_ attributes to chose the datatype.<br>
	 * The corresponding static DEFAULT_VALUE_ attribute is in effect,<br>
	 * in the case the column has notnull = true.<br>
	 * 
	 * @param name The name of the Column.
	 * @param datatype The datatype of the values this Column will contain.
	 * @param notnull Determines whether values in this Column can be null or not.
	 */
	public Column(String name, String datatype, boolean notnull) {
		this.name 		= name;
		this.datatype 	= datatype;
		this.notnull 	= notnull;
	}
	public Column(String name, String datatype)	{ this(name,datatype,false); }
	
	
	//simple getters
	public String getName() 					{ return name; 		}
	public String getDatatype() 				{ return datatype; 	}
	public boolean getNotnull()					{ return notnull;	}
	
	
	//simple setters
	public void setName(String name) 			{ this.name 	= name;		}
	public void setDatatype(String datatype)	{ this.datatype = datatype;	}
	public void setNotnull(boolean notnull) 	{ this.notnull 	= notnull;	}
	
	//complex getters
	public String getDefaultValue()		{
		if(notnull) {
			switch (datatype) {
				case SQL.DATATYPE_INT:
					return SQL.DEFAULT_VALUE_INT;
				case SQL.DATATYPE_STRING:
					return SQL.DEFAULT_VALUE_STR;
				case SQL.DATATYPE_BOOLEAN:
					return SQL.DEFAULT_VALUE_BLN;
			}
		}
		return null;
	}
	
	public String getValue(int index) {
		return data.get(index);
	}
	
	public List<String> getAllValues() {
		return new ArrayList<String>(data);
	}
	
	public int getRowCount() {
		return data.size();
	}
	
	//complex setters
	public void init() {
		data = new ArrayList<String>();
	}
	
//	public void init(int rowCount) {
//		init();
//		String defaultValue = getDefaultValue(); 
//		
//		for(int i = 0; i < rowCount; ++i) {
//			data.add(defaultValue);
//		}
//	}
	
	public void insertValue(String value) {
		data.add(value);
	}
	
	public void removeValue(int index) {
		data.remove(index);
	}
}
